--require "MainScene"

JunXiaoLayer0={}
local NodeID = {HeroTable=1001}
local HeroItemID = {ImgBK=2001, TongShuai=2002, ZhanShu=2003, BaoPo=2004, JueZhao=2005, Name=2006}

JunXiaoLayer0.getNode = function()
  JunXiaoLayer0.node = CCBReader:load("JunXiaoLayer0.ccbi")
  print("JunXiaoLayer0.getNode", JunXiaoLayer0.node)
  JunXiaoLayer0.init() 
  return JunXiaoLayer0.node
end

JunXiaoLayer0.getScene = function()
  local sc = CCScene:create()
  sc:addChild(JunXiaoLayer0.getNode())  
  print("JunXiaoLayer0.getScene", sc)
  return sc
end

JunXiaoLayer0.clear = function()
end

JunXiaoLayer0.init = function()
  JunXiaoLayer0.clear()
  JunXiaoLayer0.initTable()
end

JunXiaoLayer0.initTable = function()
  local heros = UserData.userinfo.host.store.refresh.g
  local items = CCArray:create()
  for k,v in ipairs(heros) do
    print("initArmygroupTable", k, v)
    local item = CCBReader:load("JiangLingItem.ccbi")
    local info = UserData.config.models.General[v]
    local skillName = UserData.config.models.NewSkill[info.skill].name
    local imgName = string.format("%d.png",v%40)
    local imgBK = item:getChildByTag(HeroItemID.ImgBK)
    local sp = CCSprite:create(imgName)
    sp:setScale(0.8)
    sp:setPosition(imgBK:getPosition())
    item:addChild(sp)

    local lb = item:getChildByTag(HeroItemID.Name) 
    TypeCast(lb, "CCLabelTTF"):setString(info.name)
    if info.quality=="green" then
      lb:setColor(ccc3(0,255,0))
    elseif info.quality=="blue" then
      lb:setColor(ccc3(0,0,255))
    else
      lb:setColor(ccc3(255,255,255))
    end
  
    lb = item:getChildByTag(HeroItemID.TongShuai)
    TypeCast(lb, "CCLabelTTF"):setString(tostring(info.initCommander))
    lb = item:getChildByTag(HeroItemID.ZhanShu)
    TypeCast(lb, "CCLabelTTF"):setString(tostring(info.initTactics))
    lb = item:getChildByTag(HeroItemID.BaoPo)
    TypeCast(lb, "CCLabelTTF"):setString(tostring(info.initBlast))
    lb = item:getChildByTag(HeroItemID.JueZhao)
    TypeCast(lb, "CCLabelTTF"):setString(skillName)
     
    item:setContentSize(CCSizeMake(320,190)) 
    items:addObject(item)
  end
  local tableBK = JunXiaoLayer0.node:getChildByTag(NodeID.HeroTable)
  local size = tableBK:getContentSize()
  local tableview = CCTableView:create(0, CCSizeMake(size.width-20, size.height), items)
  local x, y = ActionUtil.leftBottomPoint(tableBK)
  tableview:setPosition(x+10, y+15)
  JunXiaoLayer0.node:addChild(tableview)
end
